<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>加减计数器</title>
    <link href="./index.css" rel="stylesheet" />
</head>

<body>
    <!-- 1.html结构 -->
    <div id="app">
       <!-- 计数器功能区 -->
       <div class="input-num">
            <button v-on:click="sub()">-</button>
            <span v-text="num">{{num}}</span>
            <button v-on:click="add()">+</button>
       </div>
    </div>
    <!-- 2.开发环境版本，包含了有帮助的命令行警告 -->
    <script src="../js/vue.js"></script>
    <!-- 3.创建Vue实例 -->
    <script>
         var app=new Vue({
             el:"#app",
             data:{
                num:1
             },
             methods:{
                add(){
                    if(this.num<10){
                        this.num++;
                    }
                    else{
                        alert("累加结果大于10");
                    }
                },
                sub(){
                    if(this.num>0){
                        this.num--;
                    }
                    else{
                        alert("累减结果小于0");
                    }
                }
            },
         })
    </script>
</body>

</html>